
//导入 创建的方法 暴露router实例对象
import { createRouter, createWebHashHistory } from 'vue-router'
// 配置routerr实例对象
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/pages/login/Login.vue'),

    },
    // home
    {
        path: '/layout',
        component: () => import('@/pages/layout/Layout.vue'),

        redirect: '/home',
        children: [
            {
                path: '/home',
                component: () => import('@/pages/home/Home.vue')
            },


        ]
    },
    {
        path: '/resourcebundle',
        component: () => import('@/pages/layout/Layout.vue'),
        redirect: '/resourcebundle/resourceListCenter',
        children: [
            {
                path: '/resourceListCenter',
                component: () => import('@/pages/resourcebundle/ResourceListCenter.vue')
            },
            {
                path: '/sortClass',
                component: () => import('@/pages/resourcebundle/sortClass.vue')
            }

        ]
    }
    ,
    {
        path: '/system',
        component: () => import('@/pages/layout/Layout.vue'),
        redirect: '/system/user',
        children: [
            {
                path: '/user',
                component: () => import('@/pages/system/User.vue')
            },
            {
                path: '/systemLog',
                component: () => import('@/pages/system/SystemLog.vue')
            }

        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


// 添加全局前置守卫  
router.beforeEach((to, from, next) => {
    // 如果路由的路径是'/' 或者是未定义的路径，则重定向到'/login'  
    if (to.path === '/') {
        next('/home');
    } else {
        next(); // 继续路由  
    }
});
// 暴露
export default router;


